#! /usr/bin/env python
# -*- coding: utf-8 -*-
import importlib

from lib.conf.config import settings
from utils.url_md5 import str_md5


class PluginManager(object):
    def __init__(self):
        self.tavern_url_dict = settings.URL_ACTION  # 测试路径
        self.value = None
        self.key = None

    async def exec_plugin(self):
        """获取所有测试插件，并执行"""
        for k, v in self.tavern_url_dict.items():
            str_ = '{0}{1}'.format(settings.BASE_URL, k)
            str_k = await str_md5(str_)
            if str_k == self.key:
                module_path, func_name = v.rsplit('.', 1)
                m = importlib.import_module(module_path)
                url_cls = getattr(m, func_name)
                await url_cls(self.value)
